<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.apache.commons.lang.StringUtils,java.sql.Connection,java.sql.Statement,java.sql.ResultSet,cn.com.chec.console.dao.DBFactory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>数据表展示</title>
<%@include file="../../common/tagInclude.jsp" %>
<%@include file="../../common/headerInclude.jsp" %>
<script type="text/javascript">
	$(function() {
		$("#jvForm").validate();
	});
	function query(tblName){
		window.location = "${basePath}admin/dbTable/descTable.do?tblName=" + tblName ;
	}
	function dbDataOpr(itemName,flag){
		if(flag == '2'){
			if(!confirm('确定全部备份吗?')) return;
			window.location = "${basePath}admin/dbTable/dumpTable.do?flag=2" ;
		}
		else if(flag == '3'){
			window.location = "${basePath}admin/dbTable/schedulerPage.do" ;
		}
		else if(flag == '4'){
			window.location = "${basePath}admin/dbTable/exportList.do" ;
		}
		else{
			var all_checkbox = document.getElementsByName(itemName);
			var len = all_checkbox.length;
			if(isChecked(itemName) == false ){
				alert('至少选择一项');
			}else{
				if(!confirm('确认要备份指定数据表吗?'))return;
				var values = "";
				for(var i=0;i<len ;i++){
					if(all_checkbox[i].checked)
						values += "," + all_checkbox[i].value;
				}
				if(values.length > 1)
					values = values.substring(1);
				window.location = "${basePath}admin/dbTable/dumpTable.do?flag=1&tblNames=" + values ;
			}
		}
	}
</script>
</head>
<body>
<div class="body-box">
	<div class="rhead">
		<div class="rpos">当前位置: 首页  - 系统 - 数据表</div>
		<div class="clear"></div>
	</div>
	<form action="${basePath}admin/userInfo/list.do" method="post" style="padding-top:5px;">
		<div>
			&nbsp;&nbsp;<a href="javascript:checkAll('tblName',true);">全选</a>
			&nbsp;&nbsp;<a href="javascript:checkAll('tblName',false);">全不选</a>
			&nbsp;&nbsp;[<a href="javascript:dbDataOpr('tblName','1');">选择性备份</a>]
			&nbsp;&nbsp;[<a href="javascript:dbDataOpr('tblName','2');">全部备份</a>]
			&nbsp;&nbsp;[<a href="javascript:dbDataOpr('tblName','3');">定时备份</a>]
			&nbsp;&nbsp;[<a href="javascript:dbDataOpr('tblName','4');">数据恢复</a>]
		</div>
		<table class="pn-ltable" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
			<thead class="pn-lthead">
			<tr>
				<th>标识</th>
				<th>数据表名称</th>
				<th>存储引擎</th>
				<th>自增</th>
				<th>行数</th>
				<th>创建时间</th>
				<th>编码校对</th>
				<th>备注信息</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody class="pn-ltbody">
			<%
				boolean flag = false ;
				Connection conn = DBFactory.getInstance().getConnection();
				String showTables = "show table status" ;
				Statement stmt = conn.createStatement();
				ResultSet rs = stmt.executeQuery(showTables);
				while(rs.next()){
				%>
			<tr>
				<td align="center"><input type="checkbox" name="tblName" id="tblName" value="<%=rs.getString("name")%>"/></td>
				<td align="left"><a href="javascript:query('<%=rs.getString("name")%>');"><%=rs.getString("name")%></a></td>
				<td align="center"><%=rs.getString("engine")%></td>
				<td align="center"><%=StringUtils.isBlank(rs.getString("auto_increment")) ? "" : rs.getString("auto_increment")%></td>
				<td align="center"><%=rs.getString("rows")%></td>
				<td align="center"><%=rs.getString("create_time")%></td>
				<td align="center"><%=rs.getString("collation")%></td>
				<td><%=rs.getString("comment")%></td>
				<td align=center>
					<a href="javascript:query('<%=rs.getString("name")%>');">查询</a>
				</td>
			</tr>
			<%}rs.close();stmt.close();conn.close(); %>
			</tbody>
		</table>
	</form>
</div>
</body>
</html>